/*
 * @Author: mat
 * @Description: 对axios的简单封装
 */

import axios from 'axios'
// import { Message } from 'element-ui'

const service = axios.create({
	baseURL: config.base_url, // url = base url + request url
	// withCredentials: true, // send cookies when cross-domain requests
	timeout: 8000, // request timeout
})
service.interceptors.request.use(
	(config) => {
		return config
	},
	(error) => {
		console.log(error) // for debug
		return Promise.reject(error)
	}
)
service.interceptors.response.use(
	(response) => {
		// const res = response.data
		// if (res.status !== 200) {
		//   return Promise.reject(res)
		// } else {
		//   return res
		// }
		return response
	},
	(error) => {
		console.log('err' + error) // for debug
		// Message({
		//     message: error.message,
		//     type: 'error',
		//     duration: 5 * 1000
		// })
		return Promise.reject(error)
		// return Promise.reject(error.response.data)
	}
)
export default service
